package com.lg.partition13;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2022/4/8 16:39
 */
public class P1273有线电视网 {

    private static final int N = 3010;
    private static int[] h = new int[N], e = new int[N], ne = new int[N], w = new int[N], hw = new int[N];
    //f[i][j]表示以i为根节点，满足j个用户的需求的最大收益
    private static int[][] f = new int[N][N];
    private static int n, m, idx = 0;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = nextInt(); m = nextInt();
        Arrays.fill(h, -1);
        for (int i = 1; i <= n - m; i++) {
            int k = nextInt();
            for (int j = 0; j < k; j++) {
                int a = nextInt(), b = nextInt();
                add(i, a, b);
            }
        }
        for (int i = n - m + 1; i <= n; i++) hw[i] = nextInt();
        for (int i = 1; i <= n; i++) Arrays.fill(f[i], -0x3f3f3f3f);
        dfs(1);
        for (int i = m; i >= 1; i--) {
            if (f[1][i] >= 0) {
                writer.println(i);
                break;
            }
        }
        writer.flush();
    }

    private static int dfs(int u) {
        f[u][0] = 0;
        if (u > n - m) {
            f[u][1] = hw[u];
            return 1;
        }
        int cnt = 0;
        for (int i = h[u]; i != -1; i = ne[i]) {
            int v = e[i];
            int t = dfs(v);
            cnt += t;
            for (int j = cnt; j >= 1; j--) {
                for (int k = 1; k <= Math.min(t, j); k++) {
                    f[u][j] = Math.max(f[u][j], f[u][j - k] + f[v][k] - w[i]);
                }
            }
        }
        return cnt;
    }

    private static void add(int a, int b, int c) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx;
        w[idx++] = c;
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
